<?php
session_start();
include_once 'functions/function.php';
include_once 'functions/index.class.php';
include_once 'functions/modifyUser.class.php';

$Db = Db();


if(!isset($_SESSION['id'])){
    
     
    session_start();
    session_unset();
    session_destroy();

    header('Location: index.php');
}




if(isset($_POST['submit'])){
    
    
    $modifyUser = new modifyUser($_POST['userType'],$_POST['status'],$_POST['email']);
   
  
        
        if($modifyUser->modify() == "ok"){
            
         header("Location: manageUser.php");
            
        }
    else{
        
        $error = "Select an action or cancel the operation";
        $display = $error;
        
    }
    
}



?>




<!DOCTYPE html>
<html>
    <head>
		<link rel="stylesheet" href="css/adminHome.css">
	</head >
	
	
	<body style="background: url(images/background.jpg);">
	
	
		<div id="wrapper">
		
			<div id="head">
		
					<table id="myTable" border=0>
						<tr>
							<td class="leftCell" ><span>Hello!!<span class="newAccount"><?php echo $_SESSION['username']; ?></a></span></td>
							<td class="middleCell" ><a class="newAccount" href="adminHome.php">Home</a></td>
							<td class="rightCell" ><span><a class="newAccount" href="logOut.php">Sign out</a></span></td>
						</tr>
					</table>
		
            </div>
	
		<div id="container">
		
		
			<div id="optionSection">
                            <table border="0" id="adminHeader">
                                
                                <tr class="newForum">
                                    <td class="left"><a class="noDecoration4" href="#">Create New Forum</a></td>
                                    <td class="right"><a class="noDecoration4" href="manageUser.php">Manage Users</a></td>
                                </tr>
                                
                            </table>
			</div>
                    
                    
                    
                            <div id="myTable2">
			
				<div id="forumSectionUser">
				
                                    
                                    <?php
                                    
                                        if(isset($_GET['email'])){
                                    
                                        $_GET['email'] = htmlspecialchars($_GET['email']);
                                        
                                         $query = $Db->prepare("SELECT *FROM user where email = :email");
                                         
                                         $query2 = $Db->prepare("SELECT *FROM user where email = :email");
                                         
                                         $query->execute(array('email'=>$_GET['email']));
                                         
                                         $query2->execute(array('email'=>$_GET['email']));
                                         
                                         $response2 = $query2->fetch();
                                         
                                         $count = 1;
                                         
                                         ?>
                                        
                                    
                                    <h2 class="noDecoration5"><?php echo $response2['firstName']; echo " "; echo " "; echo $response2['lastName'];?></h2>
                                       <table border="0" id="tableUserModify">
                                           <form method="post" action="modifyUser.php?email=<?php echo $_GET['email']; ?>">
                                        
                                         <?php
                                            
                                             $response = $query->fetch();
                                                
                                            
                                          ?>
                                            
                                             
                                                
                                           <!--<tr class='cells'><td class="forum"> -->
                                           
                                           
                                           
                                       
				
                                        
						
                                            <tr>
                                                <td>First Name</td><td><?php echo $response['firstName'];?></td>
                                            </tr>
                                            <tr>
                                                <td>Last Name</td><td><?php echo $response['lastName'];?></td>
                                            </tr>
                                            <tr>
                                                <td>Email</td><td><?php echo $response['email'];?> <input  type="hidden" name="email" value="<?php echo $_GET['email'];?>"/></td>
                                            </tr>
                                            <tr>
                                                <td>User Type<br><span class="subs">Currently : <?php echo $response['role'];?></span></td>
                                                <td>
                                                        
                                                        <select name="userType">
                                                            <option value="none">Select new type</option>
                                                            <option value="user">Regular user</option>
                                                            <option value="admin">Administrator</option>
                                                        </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                
                                                <td>Ban Status<br><span class="subs">Currently : <?php if($response['isBanned']=="f"){echo "Not Banned";} else{ echo "Banned";}?></span></td>
                                               <?php
                                               
                                               
                                               if($response['id']!=$_SESSION['id'])
                                               {
                                               ?>
                                                
                                                
                                                <td>
                                                       
                                                        <select name="status">
                                                            <option value="none">Select new status</option>
                                                            <option value="t">Ban</option>
                                                            <option value="f">Allow</option>
                                                        </select>
                                                </td>
                                                <?php
                                               }
                                               else{
                                                   ?>
                                                
                                                <td>Ban Option not available for you</td>
                                                
                                                <?php
                                                   
                                               }
                                                ?>
                                            </tr>
                                            <tr>
                                                <td>Last Updated</td><td><?php echo $response['dateUpdated'];?></td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" class="submitAlign"><input id="submit" name="submit" type="submit" value="Submit Changes"/>
                                                </td>
                                            </tr>
					</form>
                                          
                                           
          
                                      
                                  
                                          
                                         
                                         </table>
                                    
                                    <p><a class="noDecoration6" href="manageUser.php"> Cancel Operation ?</a></p>
                                    <p id="error">
                                               
                                                 <?php
                                                
                                                if(isset($display)){
                                                    
                                                    echo $display;
                                                }
                                                
                                                ?>
                                                
                                                
                                            </p>
                                                
                                          <?php
                                          
                                        }
                                        ?>
                                
                                
                                     <br class="clear" />                                  
                                </div>
                                  
                                    
                                    
                                         
		
                                 
                               
                                
                                
                                <br class="clear" />         
			</div>
	
                    <br class="clear" />
		</div>
		
		<br class="clear" />
		</div>
		<br class="clear" />
                </div>	
	
	</body>
</html>
 
                                      


